﻿using System;

namespace NMA.Infrastructure.NHibernate.DomainObject
{
    using NMA.Domain.Model;
    using NMA.Infrastructure.DBC;

    public class DomainObjectFactory : IDomainObjectFactory
    {
        public virtual ICategory CreateCategory(string name, string createdUser, string updatedUser)
        {
            Check.Assert(!string.IsNullOrEmpty(name), "Name is empty");
            Check.Assert(!string.IsNullOrEmpty(createdUser), "Created User is empty");

            return new Category()
            {
                Id = Guid.NewGuid(),
                Name = name,
                CreatedDate = DateTime.Now,
                CreatedUser = createdUser,
                UpdatedDate = DateTime.Now,
                UpdatedUser = ""
            };
        }

        public INews CreateNews(string title, string shortDescription, string content, bool isPublish, 
            DateTime publishedDate, string publishedPerson, int numberOfView, byte[] image, 
            string createdUser, string updatedUser)
        {
            Check.Assert(!string.IsNullOrEmpty(title), "Title is empty");
            Check.Assert(!string.IsNullOrEmpty(shortDescription), "Short description is empty");
            Check.Assert(!string.IsNullOrEmpty(content), "Content is empty");
            Check.Assert(isPublish != null, "Is publish is null");
            Check.Assert(publishedDate != null, "Published date is null");
            Check.Assert(!string.IsNullOrEmpty(createdUser), "Created user is empty");

            return new News()
            {
                Id = Guid.NewGuid(),
                Title = title,
                ShortDescription = shortDescription,
                Content = content,
                IsPublish = isPublish,
                PublishedDate = publishedDate,
                PublishedPerson = publishedPerson,
                NumberOfView = numberOfView,
                Image = image,
                CreatedDate = DateTime.Now,
                CreatedUser = createdUser,
                UpdatedDate = DateTime.Now,
                UpdatedUser = updatedUser
            };
        }

        public IPoll CreatePoll(string name, int value, DateTime voteDate, string whoVote, string createdUser, string updatedUser)
        {
            Check.Assert(!string.IsNullOrEmpty(name), "Name is empty");
            Check.Assert(value > 0 && value <= 5, "Value must be larger than 0 and less than 6");
            Check.Assert(voteDate != null, "Vote date is null");
            Check.Assert(!string.IsNullOrEmpty(createdUser), "Created user is empty");

            return new Poll()
            {
                Id = Guid.NewGuid(),
                Name = name,
                Value = value,
                VoteDate = voteDate,
                WhoVote = whoVote,
                CreatedDate = DateTime.Now,
                CreatedUser = createdUser,
                UpdatedDate = DateTime.Now,
                UpdatedUser = updatedUser
            };
        }

        public IAudit CreateAudit(string userName, string userAction, DateTime dateEvent)
        {
            Check.Assert(!string.IsNullOrEmpty(userName), "Username is empty");
            Check.Assert(!string.IsNullOrEmpty(userAction), "UserAction is empty");
            Check.Assert(dateEvent != null, "DateEvent is null");

            return new Audit()
            {
                Id = Guid.NewGuid(),
                UserName = userName,
                UserAction = userAction,
                DateEvent = dateEvent,
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now
            };
        }

        public IResources CreateResources(string resourceType, string cultureCode, string resourceKey, string resourceValue, string createdUser, string updatedUser)
        {
            Check.Assert(!string.IsNullOrEmpty(resourceType), "Resource type is null or empty");
            Check.Assert(!string.IsNullOrEmpty(cultureCode), "Resource type is null or empty");
            Check.Assert(!string.IsNullOrEmpty(resourceKey), "Resource type is null or empty");
            Check.Assert(!string.IsNullOrEmpty(resourceValue), "Resource type is null or empty");
            Check.Assert(!string.IsNullOrEmpty(createdUser), "Resource type is null or empty");

            return new Resources() {
                 Id = Guid.NewGuid(),
                 ResourceType = resourceType,
                 CultureCode = cultureCode,
                 ResourceKey = resourceKey,
                 ResourceValue = resourceValue,
                 CreatedDate = DateTime.Now,
                 CreatedUser = createdUser,
                 UpdatedDate = DateTime.Now,
                 UpdatedUser = updatedUser
            };
        }
    }
}